package org.zero.orika.converter;

import lombok.SneakyThrows;
import ma.glasnost.orika.MappingContext;
import ma.glasnost.orika.converter.BidirectionalConverter;
import ma.glasnost.orika.metadata.Type;
import org.zero.model.constant.StatusEnum;
import org.zero.util.EnumUtils;

/**
 * @author Zero (cnzeropro@qq.com)
 * @date 2021/9/1 15:42
 */
public class StatusConverter extends BidirectionalConverter<Byte, StatusEnum> {
    @SneakyThrows
    @Override
    public StatusEnum convertTo(Byte source, Type<StatusEnum> destinationType, MappingContext mappingContext) {
        return EnumUtils.getEnum(StatusEnum.class,source);
    }

    @Override
    public Byte convertFrom(StatusEnum source, Type<Byte> destinationType, MappingContext mappingContext) {
        return EnumUtils.getKey(source, Byte.class);
    }
}
